package com.lyt.dao;

import com.lyt.bean.Paper;
import com.lyt.bean.PaperQuestion;
import com.lyt.vo.PaperVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
 * @Author: zjx
 * @Date: 2023/04/27/20:03
 * @Description:
 */
@Repository
public interface PaperDao {

    //获取paper最大id
    @Select("select paper_id from paper ORDER BY paper_id desc limit 1")
    public int  getPaperMaxId();//根据

    @Select("select * from paper where paper_id = #{paperId}")
    public Paper selectPaperByUserId(Integer paperId);//根据试卷编号查询试卷

    @Update("update paper set paper_name=#{paperName},grade=#{grade} where paper_id = #{paperId}")
    public int updatePaper(Paper paper);//根据试卷编号更新试卷名字，年级

    @Select("select * from paper where paper_id = #{paperId}")
    public Paper selectPaperByPaperId(Integer paperId);//根据试卷编号查询试卷

    @Delete("delete from paper where paper_id = #{paperId}")
    public int deletePaper(Integer paperId);//根据试卷编号删除试卷

    @Insert("insert into paper (paper_id,paper_name,score,course_id,one,two,three,"+
            "status,grade,title_content) values(#{paperId},#{paperName},#{score},#{courseId},#{one},#{two}" +
            ",#{three},#{status},#{grade},#{titleContent})")
    public int addPaper(Paper paper);//创建试卷

    @Insert("insert into paper_question values(#{id},#{paperId},#{questionId})")
    int addPaperQuestion(PaperQuestion paperQuestion);

    @Select("select * from paper where course_id = #{courseId}")
    public List<Paper> getAllByCoursePaper(int courseId);//根据课程获取所有试卷中的试题

    @Select("select * from paper where grade = #{grade}")
    public List<Paper> getAllByGradePaper(Integer grade);//根据课程获取所有试卷中的试题

    @Update("update paper set status=#{status} where paper_id = #{paperId}")
    public int commitPaper(@Param("status")Integer status,@Param("paperId")Integer paperId);//发布试卷

    @Select("select * from paper")
    public List<Paper> getAllPaper();//获取所有试卷

//    @Results(value = {@Result(id = true,column="paper_id",property="paperId"),
//            @Result(property="questions",column="paper_id",javaType = List.class,
//                    many = @Many(select = "com.lyt.dao.QuestionDao.selectByQuestionId"))
//    })
//    @Select("select * from paper")
//    public List<Paper> getAllPaperQuestion();//查询试题出现在什么试卷上
}
